//
//  FourViewController.m
//  UI_元旦豆瓣小集合
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "FourViewController.h"
#import "Mytitlemodel.h"
#import "ADataBaseHandle.h"
@interface FourViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableview;
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) NSArray *Array;

@end

@implementation FourViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的";
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    [_tableview release];
    UIBarButtonItem *rightCancelButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:(UIBarButtonItemStylePlain) target:self action:@selector(rightCancelButtonItem:)];
    self.navigationItem.rightBarButtonItem = rightCancelButtonItem;
    self.arr = [[ADataBaseHandle sharedDaseBaseHandle] selectModel];
    self.Array = @[@"我的活动", @"我的电影" , @"清理缓存"];
}

- (void)rightCancelButtonItem:(UIBarButtonItem *)buttonItem {
    FiveViewController *fVc = [[FiveViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:fVc];
    fVc.delegate = self;
    // 导航栏 颜色
    nav.navigationBar.barTintColor = [UIColor whiteColor];
    
    [self presentViewController:nav animated:YES completion:^{
        
    }];
   
}
- (void)FiveWithstring:(NSString *)string {
    UIBarButtonItem *rightCancelButtonItem = [[UIBarButtonItem alloc] initWithTitle:string style:(UIBarButtonItemStylePlain) target:self action:@selector(rightCancelButtonItem1:)];
    self.navigationItem.rightBarButtonItem = rightCancelButtonItem;
 
}

- (void)rightCancelButtonItem1:(UIBarButtonItem *)buttonItem {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否确认注销" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIBarButtonItem *rightCancelButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:(UIBarButtonItemStylePlain) target:self action:@selector(rightCancelButtonItem:)];
    self.navigationItem.rightBarButtonItem = rightCancelButtonItem;

    }];
    UIAlertAction *alertAction1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
       
    }];
    [alert addAction:alertAction];
    [alert addAction:alertAction1];
    [self presentViewController:alert animated:YES completion:^{
        
    }];
    
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
        
    }//可以用数组
   
    cell.textLabel.text = _Array[indexPath.row];
    
    return cell;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([_Array[indexPath.row]  isEqual: @"我的活动"]) {
        NineViewController *niceVC = [[NineViewController alloc] init];
        [self.navigationController pushViewController:niceVC animated:YES];
    }else if ([_Array[indexPath.row]  isEqual: @"我的电影"]){
        EightViewController *eightVC = [[EightViewController alloc] init];
        [self.navigationController pushViewController:eightVC animated:YES];
        
        
        
    }else if ([_Array[indexPath.row]  isEqual: @"清理缓存"]){
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"清理内存" message:@"是否清理内存" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *Aciton1 = [UIAlertAction actionWithTitle:@"清理" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            [[ADataBaseHandle sharedDaseBaseHandle] deleteModel];
        }];
        UIAlertAction *Action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:Aciton1];
        [alert addAction:Action2];
        [self presentViewController:alert animated:YES completion:nil];

    }
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
